<template>
  <a-card>
    <div style="height: 30px">
      <a-button
        type="primary"
        style="float: right"
        @click="$router.push('/news/addNews')"
        >新增</a-button
      >
    </div>
    <div style="height: 10px"></div>
    <a-table
      :columns="columns"
      :data-source="dataList"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="title" slot-scope="row">{{ row.title }}</span>
      <span slot="nameType" slot-scope="row">{{ row.nameType }}</span>
      <span slot="imageUrl" slot-scope="row">
        <img v-if="row.imageUrl" :src="FORM_ACTION.globalUrl + row.imageUrl" />
      </span>
      <span slot="author" slot-scope="row">{{ row.author }}</span>
      <template slot="action" slot-scope="text, record">
        <a-button size="small" @click="pub(record)" style="margin-right: 20px" >{{ record.status==1?'取消发布':'发布' }}</a-button>
        <a-button size="small" @click="editor(record)" style="margin-right: 20px" >编辑</a-button>
        <a-button size="small" type="danger" @click="del(record)">删除</a-button>
      </template>
    </a-table>
  </a-card>
</template>

<script>
import { mainMixin } from "@/mixins/main";
const columns = [
  {
    title: "标题",
    key: "title",
    ellipsis: true,
    scopedSlots: { customRender: "title" },
  },
  {
    title: "资讯类型",
    key: "nameType",
    ellipsis: true,
    scopedSlots: { customRender: "nameType" },
  },
  {
    title: "作者",
    key: "author",
    ellipsis: true,
    scopedSlots: { customRender: "author" },
  },
  {
    title: "操作",
    key: "action",
    ellipsis: true,
    scopedSlots: { customRender: "action" },
  },
];
export default {
  mixins: [mainMixin],
  data() {
    return {
      form: {
        pageVo: {
          pageNumber: 1,
          pageSize: 10,
        },
      },
      dataList: [],
      loading: false,
      columns: columns,
      url: "/rapid/news/getPage",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    editor(record) {
      console.log(record);
      this.$router.push({
        path: "/news/addNews",
        query: { id: record.id },
      });
    },
    pub(col){
      let params = { id: col.id };
      this.$http("/rapid/news/publishNew", params).then(res=>{
         if (res.code === 200) {
                this.$message.info("操作成功");
                this.getList();
            } else {
                this.$message.warning(res.message);
            }
      })
    },
    del(col) {
      let _this = this;
      let params = { id: col.id };
      this.$confirm({
        title: "确认删除",
        content: "是否删除选中数据?",
        onOk: function () {
          _this.loading = true;
          const { id } = col.id;
          _this.$http("/rapid/news/delete", params)
            .then((res) => {
              if (res.code === 200) {
                _this.$message.info("操作成功");
                _this.getList();
              } else {
                _this.$message.warning(res.message);
              }
            })
            .finally(() => {
              _this.loading = false;
            });
        },
      });
    },
  },
};
</script>

<style>
</style>
